package Verification;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Vector;
import java.util.ArrayList;

/**
 * Represents the expected sequence.
 *
 * @author Robin Lilja
 * @version 2009-09-24 2300h
 *
 */
public class Expected {

	/**
	 * Expected representation as list of array strings.
	 */
	private ArrayList<String> expected;

	/**
	 * Alphabet constructor.
	 *
	 * @param file File to load alphabet from
	 */
	public Expected(String file) {

		try {

			this.expected = readFromFile(file);

		} catch (Exception e) {

			System.out.println(e);
		}

	}

	public boolean assertFoundMore(ArrayList<String> found) {

		return expected.size() < found.size();
	}

	/**
	 * Asserts that the expected solutions are a subset of the found solutions.
	 *
	 * @param found Found solutions as an array list of strings
	 * @return True if expected is a subset of found
	 */
	public boolean assertSubsetOf(ArrayList<String> found) {

		for(String sequence : expected) {
			
			// The found does not contain expected sequence
			if (!found.contains(sequence + " ")) {

				return false;

			}
		}

		return true;
	}

	/**
	 * Loads a expected sequence from specified file.
	 *
	 * @param file File to load from
	 * @throws Exception - FileNotFound
	 * @return List of strings containing the alphabet
	 */
	private ArrayList<String> readFromFile(String file) throws Exception {

		ArrayList<String> list = new ArrayList<String>();

		BufferedReader in = new BufferedReader(new FileReader(file));

		String s;

		do {

			s = in.readLine();

			if (s != null) {

				list.add(s);

			}

		} while (s != null);

		in.close();

		return list;
	}

	/**
	 * Prints expected to console.
	 *
	 */
	public void toConsole() {

		System.out.println("Expected:");

		for(String sequence : expected) {
			System.out.println(sequence);
		}

		System.out.print("\n\n");

	}
}
